home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
kh_gdi.zip
/
KH_GDI.TXT
< prev
next >
Wrap
Text File
|
1996-06-03
|
19KB
|
631 lines
KNOW-HOW GDI Shell v. 1.0
(C) Stepan S.Vartanov, 1995 - 96
1. Features.
* KNOW-HOW GDI Shell v. 1.0 is the WINAPI GDI functions wrapper.
Its primary purpose is to hide drawing details, such as scaling,
scrolling and rotations of the image.
* ver. 1.0 supports vector graphics only (no bitmaps).
* KNOW-HOW GDI Shell is a class library, you can instantiate its
classes or derive your own classes from them.
* Ver. 1.0 was not tested with Windows 95 - it will be changed in ver.
1.2
* Ver. 1.0 uses Borland BGI fonts for text output (zoom, rotate are
available). TRUE TYPE fonts support will be added in ver. 1.1 and will
be available in COMMERCIAL (non-SHAREWARE) version only.
2. Usage.
As with any class library there are few possible approaches. Some
suggested approaches are described below. See also KH_DEMO project.
We are going to produce picture of the 'bird'.
// Put this code in application main file
// This let you to init drawTool only once
#include "drawtool.h"
...
YourApplication::Init()
{
...
// Create drawTool in application's destructor
drawTool = new KH_Paint();
...
}
YourApplication::~YourApplication()
{
....
delete drawTool;
....
}
Use drawTool drawing functions:
#include "drawtool.h"
MyWindow::draw()
{
drawTool->line(100, 100, 200, 300)
}
Another approach (used in example) uses
inheritance:
#include "bgipaint.h"
class MyWindow : public KH_Paint
{
...
drawPig(x, y); // Your function
...
};
....
MyWindow::drawPig(int x, int y)
{
line(100, 100, 200, 300);
....
}
3. Classes and Functions.
File BGI_FONT.H
Class encapsulates BGI fonts (*.chr) description. BGI fonts are not
documented. I use existing format.
struct _export BGI_Font : public AbstractGraphics
{
...
// Deformation of an image
uchar multx, multy, divx, divy;
// Create object and load() (BGI) font.
BGI_Font(char* fileName = 0);
~BGI_Font();
// Remove old and load new font. Fomt should
// exist, or NULL is loaded
void load(char* fileName);
// Character output
int draw_char(int x,int y,char c, int dir=0);
// Line of characters
int outtextxy(int x, int y, char* str, int
dir = 0);
// Overload when API accessible
void outtext(char* str) {}
// Width of text, pixels (not rotated)
int gettextwidth(char* str);
// Heigth of text, pixels (not rotated)
int getheight() { return CapitalHeight; }
// Set character deformation
void setusercharsize(int mx, int dx, int my,
int dy)
{multx=mx; multy=my; divx=dx; divy=dy; }
// Set text justification
void settextjustify(int j,int k)
{h_just=j;v_just = k; }
};
FILE DRAWTOOL.H
Defines global drawing object - in the case if you do not want to use
inheritance. This is not part of library - just an example.:
#ifndef __KH_PAINT_H_
#define __KH_PAINT_H_
#include "bgipaint.h"
extern KH_Paint* drawTool;
FILE BGIPAINT.H
User will probably work only with this file. Real API functions of
Windows are available to this class(es).
// Convenient names - you can use any set - Windows, if your are more
used to it, or Borland BGI-like names:
#define SOLID_FILL 1
#define SOLID_LINE PS_SOLID
#define DASHED_LINE PS_DASH
#define DOTTED_LINE PS_DOT
#define CENTER_LINE PS_DASHDOT
// Do not use HS_BDIAGONAL, HS_FDIAGONAL,
// VS_VERTICAL, HS_HORIZONTAL HS_CROSS and
// HS_DIAGCROSS !!!
#define LINE_FILL 0
#define HATCH_FILL 2
#define SLASH_FILL 3
#define XHATCH_FILL 4
#define BKSLASH_FILL 5
#define LTSLASH_FILL 6
#define LEFT_TEXT 0
#define CENTER_TEXT 1
#define RIGHT_TEXT 2
#define BOTTOM_TEXT 0
#define TOP_TEXT 2
#define HS_SOLID SOLID_FILL
enum COLORS { BLACK, BLUE, GREEN, CYAN, RED,
MAGENTA, BROWN, LIGHTGRAY, DARKGRAY, LIGHTBLUE,
LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA,
YELLOW, WHITE };
// Use this structure to reference collors in 16
colors scale
struct color_to_16
{
int color;
COLORREF colorref;
};
// Descriptions of colors
static color_to_16 tricolors[16] =
{ { BLACK, 0 },
{ BLUE, RGB(0, 0, 128) },
{ GREEN, RGB(0, 128, 0) },
{ CYAN, RGB(0, 128, 128) },
{ RED, RGB(128, 0, 0) },
{ MAGENTA, RGB(74, 23, 74) },
{ BROWN, RGB(128, 64, 64) },
{ LIGHTGRAY, RGB(128, 128, 128) },
{ DARKGRAY, RGB(64, 64, 64) },
{ LIGHTBLUE, RGB(0, 0, 255) },
{ LIGHTGREEN, RGB(0, 255, 0) },
{ LIGHTCYAN, RGB(0, 255, 255) },
{ LIGHTRED, RGB(255, 0, 0) },
{ LIGHTMAGENTA, RGB(255, 0, 255) },
{ YELLOW, RGB(255,255,30) },
{ WHITE, RGB(255, 255, 255) }
};
// There are some reasons why this class is not
part of
// KH_Paint. However under normal circumstances
user will never use it
// directly
struct _export To_Paint
{
int PenSize;
int PenStyle;
COLORREF color;
int pattern_num;
int fill_color;
COLORREF BrushColor;
HDC DC;
/////////////////////////////////
To_Paint() { pattern_num = SOLID_FILL;
PenSize = 1; PenStyle = PS_SOLID;
color = RGB(0,0,0);
BrushColor = RGB(0,0,0); }
/////////////////////////////////
int getx()
{ POINT p; ::GetCurrentPositionEx(DC,
&p); return p.x; }
int gety()
{ POINT p; ::GetCurrentPositionEx(DC,
&p); return p.y; }
COLORREF getcolorref() { return color; }
int getcolor(COLORREF col);
int getcolor() { return getcolor(color); }
void setcolor(int r, int g, int b)
{ color = RGB(r,g,b); }
void setcolor(int c)
{ color = tricolors[c].colorref; }
void putpixel(int x, int y)
{ ::SetPixel(DC, x, y, getcolorref()); }
void setlinestyle(int width, int style)
{ PenSize = width; PenStyle = style; }
void setlinestyle(int style, unsigned int,
int width)
{ PenSize = width; PenStyle = style; }
void setfillstyle(int style, int col)
{
pattern_num = style;
fill_color = col;
BrushColor = tricolors[col].colorref;
}
void setfillstyle(int style, COLORREF col)
{
pattern_num = style;
BrushColor = col;
}
void moveto(int x, int y) { ::MoveTo(DC, x,
y); }
void lineto(int x, int y);
void fillpoly(int numpoints, int*
polypoints);
void drawpoly(int numpoints, int far*
points);
};
File BGIPAINT.H
KH_Paint class could be considered as the main class in the library.
struct _export KH_Paint : public To_Paint,
public Paint
{
KH_Paint() : To_Paint(), Paint() {}
int getx();
int gety();
loc get_CP();
void putpixel(int x, int y);
void line(int xstart, int ystart, int xend,
int yend)
{ moveto(xstart, ystart); lineto(xend,
yend); }
void lineto(int x, int y);
void moveto(int x, int y);
void circle(int x, int y, int radius)
{ ellipse(x, y, 0, 360, radius, radius);}
void ellipse(int x, int y, int stangle, int
endangle, int xr, int yr);
void rectangle(int left, int top, int right,
int bottom);
void drawpoly(int numpoints, int far*
points);
void fillpoly(int numpoints, int far* points)
{ int f = fill; fill = ON;
drawpoly(numpoints,points); fill = f; }
void bar3d(int l, int t, int r, int b, int d,
int top);
virtual void outtext(char* str, int dir = 0);
void set_fill(int state) { fill = state; }
};
FILE PAINT.H
Encapsulates axes transformation routines. Rotation could be
simply processed if it is single operation. To use nested rotations we use
stack of rotations info structures.
Example of complex rotation:
void f1(int x, int y, int alpha)
{ ... perform rotation ... }
void f2(int x, int y, int alpha)
{ rotate(10,10,90); f1(x, y, alpha); }
Fu